home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / worldsrc.zip / VTXTCN.C < prev    next >
C/C++ Source or Header  |  1992-08-13  |  4KB  |  152 lines

  1. #include <stdio.h>
  2. /* World C Version 1.00 copyright 1987 J.D.McDonald 
  3.    Use as you like for non-commercial purposes, but please
  4.    leave this note, and document any changes you make as yours */
  5.  
  6. long            z, zbig, zsmall;
  7. long            htext[2000];
  8. int             gtext[5];
  9. char            chrbuf[90];
  10. FILE           *vtext_dat, *qtext_inc, *objdes_inc;
  11. FILE           *gtext_inc;
  12. int             q1text_dat;
  13. short           packch;
  14. int             i, u, kk, nold, size, number, nnmax, kq;
  15. short           buffer[512];
  16. int             bi;
  17. main()
  18. {
  19.  
  20.     vtext_dat = fopen("vtext.dat", "r");
  21.     q1text_dat = creat("q1text.dat", 0600);
  22.     qtext_inc = fopen("qtext.inc", "w");
  23.     objdes_inc = fopen("objdes.inc", "w");
  24.  
  25.     fprintf(objdes_inc, " short odistb[] = { 0 \n");
  26.     for (i = 0; i < 2000; i++)
  27.     htext[i] = 0;
  28.     z = 0;
  29.     zbig = 0;
  30.     zsmall = 0;
  31.     u = 0;
  32.     nold = 0;
  33.     bi = 0;
  34.  
  35.     do {
  36.     fgets(chrbuf, 80, vtext_dat);
  37.     for (i = 0; i < 85; i++) {
  38.         if (chrbuf[i] == '\012' || chrbuf[i] == '\015' || chrbuf[i]
  39.         == '\0')
  40.         break;
  41.     }
  42.     size = i;
  43.     for (i = size - 1; i > 3; i--) {
  44.         if (chrbuf[i] != ' ')
  45.         break;
  46.     }
  47.     size = i + 1;
  48.     if (size < 9) {
  49.         chrbuf[8] = ' ';
  50.         size = 9;
  51.     }
  52.     number = atoi(chrbuf);
  53.  
  54.     if (number != nold)
  55.         u += 1;
  56.     if (number < 1001)
  57.         gtext[1] = u;
  58.     if (number < 2001)
  59.         gtext[2] = u;
  60.     if (number < 3001)
  61.         gtext[3] = u;
  62.     if (number < 9999)
  63.         gtext[4] = u;
  64.     if (number > 3000 && number < 3999) {
  65.         fprintf(objdes_inc, "  , %6d \n", u);
  66.         nnmax = number - 3000;
  67.     } else if (number > 5000 && number < 5999) {
  68.         fprintf(objdes_inc, "   , %6d \n", u);
  69.     } else;
  70.     if (number != nold)
  71.         htext[u] = z;
  72.     nold = number;
  73.     chrbuf[size] = '{';
  74.     for (i = size + 1; i < 90; i++)
  75.         chrbuf[i] = '}';
  76.     for (i = 8; i < size; i++) {
  77.         if (chrbuf[i] == ' ')
  78.         chrbuf[i] = '`';
  79.         if (chrbuf[i] == '.')
  80.         chrbuf[i] = '|';
  81.     }
  82.     kk = 8;
  83.     while (1) {
  84.         if (bi == 512)
  85.         dump_buf();
  86.  
  87.         if (chrbuf[kk] < '`' || chrbuf[kk + 1]
  88.         < '`' || chrbuf[kk + 2] < '`') {
  89.         packch = -(chrbuf[kk] + (chrbuf[kk + 1] << 8));
  90.         buffer[bi] = packch;
  91.         kk += 2;
  92.         zbig++;
  93.         bi++;
  94.         z++;
  95.         if (chrbuf[kk - 1] == '{' || chrbuf[kk - 2] == '{')
  96.             break;
  97.         } else {
  98.         packch = (chrbuf[kk + 2] - 96) * 1024 + (chrbuf[kk + 1] - 96)
  99.                     * 32 + chrbuf[kk] - 96;
  100.         if ((packch & 0377) == 10 || ((packch >> 8) & 0377) == 10) {
  101.             packch = -(chrbuf[kk] + (chrbuf[kk + 1] << 8));
  102.             buffer[bi] = packch;
  103.             kk += 2;
  104.             zbig++;
  105.             bi++;
  106.             z++;
  107.             if (chrbuf[kk - 1] == '{' || chrbuf[kk - 2] == '{')
  108.             break;
  109.         } else {
  110.             buffer[bi] = packch;
  111.             kk += 3;
  112.             zsmall++;
  113.             bi++;
  114.             z++;
  115.             if (chrbuf[kk - 1] == '{' || chrbuf[kk - 2] == '{' ||
  116.             chrbuf[kk - 3] == '{')
  117.             break;
  118.         }
  119.         }
  120.     }
  121.     } while (number != 9999);
  122.     dump_buf();
  123.     fprintf(objdes_inc, "  } ; \n");
  124.     u = ((u + 2) / 3) * 3;
  125.     fprintf(qtext_inc, "#define RTSIZE %6d \n", u + 1);
  126.     fprintf(qtext_inc, " unsigned short rtext[] = { 0 \n");
  127.  
  128.     for (kk = 1; kk <= u / 3; kk++) {
  129.     kq = (kk - 1) * 3;
  130.     fprintf(qtext_inc, " , %5ld, %5ld, %5ld \n", htext[kq + 1],
  131.         htext[kq + 2], htext[kq + 3]);
  132.     }
  133.     fprintf(qtext_inc, "  }; \n");
  134.  
  135.     fclose(vtext_dat);
  136.     close(q1text_dat);
  137.     fclose(qtext_inc);
  138.     fclose(objdes_inc);
  139.     gtext_inc = fopen("gtext.inc", "w");
  140.     fprintf(gtext_inc, "  int gtext[5] = { 0, %6d, %6d, %6d, %6d };\n"
  141.         ,gtext[1], gtext[2], gtext[3], gtext[4]);
  142.     fclose(gtext_inc);
  143.     printf(" packed: %8ld unpacked: %8ld \n", zsmall, zbig);
  144.     return(0);
  145. }
  146.  
  147. dump_buf()
  148. {
  149.     write(q1text_dat, buffer, 512*sizeof(short));
  150.     bi = 0;
  151. }
  152.